<template>
	<view class="comment">
		<view class="order_info comment_info">
			<view class="order_box flex-row-between">
				<image :src="goodsobj.logo" mode="" class="orderi_img"></image>
				<view class="flex-column-between orderi_box">
					<view class="font-333333 font13">{{goodsobj.goods_name}}</view>
					<view class="orderi_norms flex-row-start font-666666 font12">
						<text>规格: {{goodsobj.spec_type==10?'默认':goodsobj.goods_attr}}</text>
					</view>
					<view class="comment_img flex-row-between">
						<view class="flex-row-start" @click="Ongrade(1)">
							<image v-if="data_is.grade == 1"
								src="https://static.newbeaconhotels.com/app/D2103-business-js/shop/cot_c1.png" mode=""></image>
							<image v-else src="https://static.newbeaconhotels.com/app/D2103-business-js/shop/cot_c2.png" mode="">
							</image>
							<text class="font-333333 font13">好评</text>
						</view>
						<view class="flex-row-start" @click="Ongrade(2)">
							<image v-if="data_is.grade == 2"
								src="https://static.newbeaconhotels.com/app/D2103-business-js/shop/cot_b1.png" mode=""></image>
							<image v-else src="https://static.newbeaconhotels.com/app/D2103-business-js/shop/cot_b2.png" mode="">
							</image>
							<text class="font-333333 font13">中评</text>
						</view>
						<view class="flex-row-start" @click="Ongrade(3)">
							<image v-if="data_is.grade == 3"
								src="https://static.newbeaconhotels.com/app/D2103-business-js/shop/cot_a1.png" mode=""></image>
							<image v-else src="https://static.newbeaconhotels.com/app/D2103-business-js/shop/cot_a2.png" mode="">
							</image>
							<text class="font-333333 font13">差评</text>
						</view>
					</view>
				</view>
			</view>
			<view class="font-333333 font13">评价内容</view>
			<textarea class="comment_textarea font13 font-1e1e1e" placeholder-class="comment_placeholder"
				placeholder="请输入评价内容" @input="Oncontent" />
			<view class="font-333333 font13">买家秀</view>
			<view class="comment_photo">
				<Comupload ref="Comupload" :options="uploadObj" @callback="chooseImg"></Comupload>
			</view>
		</view>

		<!-- 提交按钮 -->
		<view class="comment_submit flex-row-center font-ffffff font15" @click="Onsubmit">
			<view class="flex-row-center">提交评论</view>
		</view>
		<view class="comment_submitx"></view>
	</view>
</template>

<script>
	import Comupload from '@/components/j-Comupload/index.vue';
	export default {
		components: {
			Comupload
		},
		data() {
			return {
				//上传图片组件
				uploadObj: {
					max: 6,
					height: 200,
					width: 200,
					radius: 20,
					top: 20,
					bottom: 0,
					right: 22,
					num: 3
				},
				obj: {}, //数据
				imgFullUrl: this.$Config.http_static, //图片地址
				code: null, //ID
				dataobj: {}, //总数据
				goodsobj: {}, //商品数据
				//提交数据
				data_is: {
					grade: 1,
					imgList: [],
					content: ''
				},
				uploadList: [], //图片数组
			}
		},
		onLoad: function(options) {
			let query = {}
			if (this.$Route.query.scene) {
				query = this.$base.OnWxoptions(this.$Route.query.scene)
			}else{
				query = options
			}
			this.code = query.code
			//详情
			this.OnOrder()

		},
		methods: {
			//详情
			OnOrder() {
				this.$Http({
					url: 'detailsOrder',
					token: true,
					data: {
						order_code: this.code
					},
					type: 'POST'
				}).then(res => {
					if (res.code == 1) {
						res.data.order_goods.logo = this.imgFullUrl + res.data.order_goods.logo
						this.dataobj = res.data
						this.goodsobj = res.data.order_goods
					}
				});
			},
			//选择评价
			Ongrade(data) {
				this.data_is.grade = data
			},
			//评价内容
			Oncontent(e) {
				this.data_is.content = e.detail.value
			},
			// 上传图片组
			chooseImg(e) {
				this.uploadList = e
			},
			//提交评论
			Onsubmit() {
				let data = {
					order_id: this.dataobj.id,
					appraise_grade: this.data_is.grade,
					appraise_img: '',
					appraise_content: this.data_is.content
				}
				let img = ''
				console.log(this.uploadList, 'look')
				if (this.uploadList.length > 0) {
					this.uploadList.forEach(item => {
						img = img + item + ','
					})
				} else {
					img = ''
				}
				img = img.substr(0, img.length - 1);
				data.appraise_img = img
				this.$Http({
					url: 'orderAppraise',
					data: data,
					type: 'POST',
					token:true,
				}).then(res => {
					if (res.code == 1) {
						let that = this
						uni.showModal({
							title: '操作提示',
							content: '提交成功,感谢您的宝贵意见~',
							confirmText: '我知道了',
							confirmColor: '#03004c',
							showCancel: false,
							success(res) {
								if (res.confirm) {
									that.$Router.replace('/pages/group/orderList')
								}
							}
						})
					} else {
						uni.showToast({
							icon: 'none',
							duration: 2000,
							title: res.msg
						});
					}
				});
			}
		}
	}
</script>

<style lang="less">
	@import url("style.less");
</style>
